local extension = Package:new("lq__standard")
extension.extensionName = "lq_reforge"

local U = require "packages/utility/utility"

Fk:loadTranslationTable{
  ["lq__standard"] = "标准包",
}

-- 曹操
local lq_refg__caocao = General:new(extension, "lq_refg__caocao", "wei", 4)
local lq__jianxiong = fk.CreateTriggerSkill{
  name = "lq__jianxiong",
  anim_type = "masochism",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and #player.room.logic:getActualDamageEvents(1, function(e)
      return e.data[1].to == player
    end) ~= 0 then
      local room = player.room
      local ids = {}
      room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
        for _, move in ipairs(e.data) do
          if move.toArea == Card.DiscardPile then
            for _, info in ipairs(move.moveInfo) do
              if room:getCardArea(info.cardId) == Card.DiscardPile then
                table.insertIfNeed(ids, info.cardId)
              end
            end
          end
        end
      end, Player.HistoryTurn)
      if #ids >= 2 then
        self.cost_data = ids
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ids = table.simpleClone(self.cost_data)
    if #ids > 2 then
      local cards, _ = U.askforChooseCardsAndChoice(player, ids, {"OK"}, self.name,
      "#lq__jianxiong-choose", nil, 2, 2)
      if #cards > 0 then
        ids = cards
      end
    end
    room:moveCardTo(ids, Card.PlayerHand, player, fk.ReasonPrey, self.name)
  end,
}
lq_refg__caocao:addSkill(lq__jianxiong)
Fk:loadTranslationTable{
  ["lq_refg__caocao"] = "曹操",
  ["#lq_refg__caocao"] = "何负天下",
  ["designer:lq_refg__caocao"] = "洛清",
  ["illustrator:lq_refg__caocao"] = "青骑士",

  ["lq__jianxiong"] = "奸雄",
  [":lq__jianxiong"] = "你受到过伤害的回合结束时，你可以从弃牌堆获得两张本回合进入其中的牌。",
  ["#lq__jianxiong-choose"] = "奸雄：请获得其中两张牌",

  ["$lq__jianxiong1"] = "燕雀，安知鸿鹄之志！",
  ["$lq__jianxiong2"] = "夫英雄者，胸怀大志，腹有良谋！",
  ["~lq_refg__caocao"] = "华佗何在？……",
}

-- 司马懿（界司马懿复制人……？）
local lq_refg__simayi = General:new(extension, "lq_refg__simayi", "wei", 3, 3)
local lq__langgu = fk.CreateTriggerSkill{
  name = "lq__langgu",
  anim_type = "masochism",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.from and not data.from.dead and not data.from:isNude()
  end,
  on_trigger = function(self, event, target, player, data)
    self.cancel_cost = false
    for i = 1, data.damage do
      if i > 1 and (self.cancel_cost or data.from.dead or data.from:isNude() or not player:hasSkill(self)) then break end
      self:doCost(event, target, player, data)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room:getOtherPlayers(player, false), function(p)
      return not p:isAllNude()
    end)
    local to = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#lq__langgu-invoke", self.name, true)
    if to[1] then
      self.cost_data = to[1]
      return true
    end
    self.cancel_cost = true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local victim = room:getPlayerById(self.cost_data)
    local hand = victim.player_cards[Player.Hand]
    local equip = victim.player_cards[Player.Equip]
    local judge = victim.player_cards[Player.Judge]
    local card_data = {}
    if #hand ~= 0 then table.insert(card_data, {"$Hand", hand}) end
    if #equip ~= 0 then table.insert(card_data, {"$Equip", equip}) end
    if #judge ~= 0 then table.insert(card_data, {"$Judge", judge}) end
    local card = room:askForCardChosen(player, victim, {card_data = card_data}, self.name)
    room:obtainCard(player, card, false, fk.ReasonPrey)
  end
}
local lq__guicai = fk.CreateTriggerSkill{
  name = "lq__guicai",
  anim_type = "control",
  events = {fk.AskForRetrial},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local card = room:askForCard(player, 1, 1, true, self.name, true, ".|.|.|hand,equip",
    "#lq__guicai-ask::" .. target.id .. ":" .. data.reason)
    if #card > 0 then
      room:doIndicate(player.id, {target.id})
      self.cost_data = card[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:retrial(Fk:getCardById(self.cost_data), player, data, self.name)
  end,
}
lq_refg__simayi:addSkill(lq__langgu)
lq_refg__simayi:addSkill(lq__guicai)
Fk:loadTranslationTable{
  ["lq_refg__simayi"] = "司马懿",
  ["#lq_refg__simayi"] = "青史新篇",
  ["designer:lq_refg__simayi"] = "洛清",
  ["illustrator:lq_refg__simayi"] = "木美人",

  ["lq__langgu"] = "狼顾",
  [":lq__langgu"] = "当你受到1点伤害后，可以观看一名其他角色的手牌，然后获得其区域内一张牌。",
  ["lq__guicai"] = "鬼才",
  [":lq__guicai"] = "当判定结果确定前，你可用一张牌代替之。",
  ["#lq__langgu-invoke"] = "狼顾：你可以观看一名其他角色的手牌，然后获得其区域内一张牌",
  ["#lq__guicai-ask"] = "鬼才：你可用一张牌代替 %dest 的 %arg 判定",

  ["$lq__langgu1"] = "以静为动，反客为主！",
  ["$lq__langgu2"] = "我之鬼谋，通天彻地！",
  ["$lq__guicai1"] = "天命难违？哈哈哈哈哈……",
  ["$lq__guicai2"] = "才通天地，逆天改命！",
  ["~lq_refg__simayi"] = "我的气数，就到这里了么？",
}

-- 夏侯惇（标夏侯惇复制人……？）
local lq_refg__xiahoudun = General:new(extension, "lq_refg__xiahoudun", "wei", 4)
local lq__ganglie = fk.CreateTriggerSkill{
  name = "lq__ganglie",
  anim_type = "masochism",
  events = {fk.Damaged},
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1, "#lq__ganglie-invoke", self.name, true)
    if to[1] then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local from = room:getPlayerById(self.cost_data)
    room:damage{
      from = player,
      to = from,
      damage = 1,
      skillName = self.name,
    }
  end
}
lq_refg__xiahoudun:addSkill(lq__ganglie)
Fk:loadTranslationTable{
  ["lq_refg__xiahoudun"] = "夏侯惇",
  ["#lq_refg__xiahoudun"] = "孤目罗刹",
  ["designer:lq_refg__xiahoudun"] = "洛清",
  ["illustrator:lq_refg__xiahoudun"] = "DH",
  ["lq__ganglie"] = "刚烈",
  [":lq__ganglie"] = "当你受到伤害后，你可以对一名角色造成1点伤害。",
  ["#lq__ganglie-invoke"] = "刚烈：你可以对一名角色造成1点伤害",

  ["$lq__ganglie1"] = "哪个敢动我！",
  ["$lq__ganglie2"] = "伤我者，十倍奉还！",
  ["~lq_refg__xiahoudun"] = "诸多败绩，有负丞相重托。",
}

-- 张辽（标张辽复制人……）
local lq_refg__zhangliao = General:new(extension, "lq_refg__zhangliao", "wei", 4)
local lq__tuxi = fk.CreateTriggerSkill{
  name = "lq__tuxi",
  anim_type = "control",
  events = {fk.EventPhaseChanging},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.to == Player.Draw and
      table.find(player.room:getOtherPlayers(player, false), function(p) return not p:isKongcheng() end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(table.filter(room:getOtherPlayers(player, false), function(p)
      return not p:isKongcheng() end), Util.IdMapper)

    local result = room:askForChoosePlayers(player, targets, 1, 2, "#lq__tuxi-ask", self.name)
    if #result > 0 then
      room:sortPlayersByAction(result)
      self.cost_data = {tos = result}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, id in ipairs(self.cost_data.tos) do
      if player.dead then break end
      local p = room:getPlayerById(id)
      if not p.dead and not p:isKongcheng() then
        local c = room:askForCardChosen(player, p, "h", self.name)
        room:obtainCard(player.id, c, false, fk.ReasonPrey)
      end
    end
    player:skip(data.to)
    return true
  end,
}
lq_refg__zhangliao:addSkill(lq__tuxi)
Fk:loadTranslationTable{
  ["lq_refg__zhangliao"] = "张辽",
  ["#lq_refg__zhangliao"] = "锋过襟声",
  ["designer:lq_refg__zhangliao"] = "洛清",
  ["illustrator:lq_refg__zhangliao"] = "KayaK",
  ["lq__tuxi"] = "突袭",
  [":lq__tuxi"] = "你可以跳过摸牌阶段，获得至多两名其他角色各一张手牌。",
  ["#lq__tuxi-ask"] = "突袭：你可以跳过摸牌阶段，获得至多两名其他角色各一张手牌",

  ["$lq__tuxi1"] = "哼，没想到吧！",
  ["$lq__tuxi2"] = "拿来吧！",
  ["~lq_refg__zhangliao"] = "真的没想到……",
}

-- 许褚
local lq_refg__xuchu = General:new(extension, "lq_refg__xuchu", "wei", 4)
local lq__luoyi = fk.CreateTriggerSkill{
  name = "lq__luoyi",
  anim_type = "offensive",
  events = {fk.DamageCaused},
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#lq__luoyi-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    data.damage = data.damage + 1
    if not room:askForDiscard(player, 1, 1, true, self.name, true, ".|.|.|.|.|armor", "#lq__luoyi-discard")[1] then
      room:invalidateSkill(player, self.name, "-turn")
    end
  end
}
lq_refg__xuchu:addSkill(lq__luoyi)
Fk:loadTranslationTable{
  ["lq_refg__xuchu"] = "许褚",
  ["#lq_refg__xuchu"] = "鹰瞵虎视",
  ["designer:lq_refg__xuchu"] = "洛清",
  ["illustrator:lq_refg__xuchu"] = "巴萨小马",
  ["lq__luoyi"] = "裸衣",
  [":lq__luoyi"] = "当你造成伤害时，你可以令此伤害+1，然后你选择一项：1.弃置一张防具牌；2.本回合此技能失效。",
  ["#lq__luoyi-invoke"] = "裸衣：你可以令此伤害+1，然后你弃置一张防具牌或令本回合此技能失效",
  ["#lq__luoyi-discard"] = "裸衣：你需弃置一张防具牌，否则本回合此技能失效",

  ["$lq__luoyi1"] = "过来打一架，对，就是你！",
  ["$lq__luoyi2"] = "废话少说，放马过来吧！",
  ["~lq_refg__xuchu"] = "丞相，末将尽力了！",
}

-- 郭嘉（界郭嘉复制人）
local lq_refg__guojia = General:new(extension, "lq_refg__guojia", "wei", 3, 3)
local lq__tiandu = fk.CreateTriggerSkill{
  name = "lq__tiandu",
  anim_type = "drawcard",
  events = {fk.FinishJudge},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.room:getCardArea(data.card) == Card.Processing
  end,
  on_use = function(self, event, target, player, data)
    player.room:obtainCard(player.id, data.card, true, fk.ReasonJustMove)
  end,
}
local lq__yiji = fk.CreateTriggerSkill{
  name = "lq__yiji",
  anim_type = "masochism",
  events = {fk.Damaged},
  on_trigger = function(self, event, target, player, data)
    self.cancel_cost = false
    for i = 1, data.damage do
      if i > 1 and (self.cancel_cost or not player:hasSkill(self)) then return false end
      self:doCost(event, target, player, data)
    end
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askForSkillInvoke(target, self.name, data) then return true end
    self.cancel_cost = true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(2, self.name)
    if player.dead or player:isKongcheng() then return end
    room:askForYiji(player, player:getCardIds("h"), room:getOtherPlayers(player, false), self.name, 0, 2)
  end
}
lq_refg__guojia:addSkill(lq__tiandu)
lq_refg__guojia:addSkill(lq__yiji)
Fk:loadTranslationTable{
  ["lq_refg__guojia"] = "郭嘉",
  ["#lq_refg__guojia"] = "一世风华",
  ["designer:lq_refg__guojia"] = "洛清",
  ["illustrator:lq_refg__guojia"] = "石蝉",
  ["lq__tiandu"] = "天妒",
  [":lq__tiandu"] = "当你的判定牌生效后，你可以获得之。",
  ["lq__yiji"] = "遗计",
  [":lq__yiji"] = "当你受到1点伤害后，你可以摸两张牌，然后你可以将至多两张手牌交给一至两名其他角色。",

  ["$lq__tiandu1"] = "天下本无事，庸人自扰之。",
  ["$lq__tiandu2"] = "天数可窥，然终不可逆！",
  ["$lq__yiji1"] = "君怜我才，我晓君志！",
  ["$lq__yiji2"] = "逸骏骋天，可瞻天数！",
  ["~lq_refg__guojia"] = "行事逆天，已知天命不眷……！",
}

-- 甄姬（标甄姬复制人……？）
local lq_refg__zhenji = General:new(extension, "lq_refg__zhenji", "wei", 3, 3, General.Female)
local lq__luoshen = fk.CreateTriggerSkill{
  name = "lq__luoshen",
  anim_type = "drawcard",
  events = {fk.TurnStart},
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".|.|spade,club",
      skipDrop = true
    }
    local judges = {
      who = player,
      reason = self.name,
      pattern = ".",
      skipDrop = true
    }
    room:judge(judge)
    if judge.card.color == Card.Black and player:isAlive() then
      room:judge(judges)
    end
    local cards = {}
    for _, card in ipairs({judge.card, judges.card}) do
      if card and room:getCardOwner(card) == nil then
        table.insert(cards, card.id)
      end
    end
    if not cards[1] then return end
    room:obtainCard(player, cards)
  end,
}
local lq__qingguo = fk.CreateViewAsSkill{
  name = "lq__qingguo",
  anim_type = "defensive",
  pattern = "jink",
  prompt = "#lq__qingguo",
  card_filter = function(self, to_select, selected)
    if #selected == 1 then return false end
    return Fk:getCardById(to_select).color == Card.Black
      and Fk:currentRoom():getCardArea(to_select) == Player.Hand
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("jink")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
}
lq_refg__zhenji:addSkill(lq__luoshen)
lq_refg__zhenji:addSkill(lq__qingguo)
Fk:loadTranslationTable{
  ["lq_refg__zhenji"] = "甄姬",
  ["#lq_refg__zhenji"] = "洛水片红",
  ["designer:lq_refg__zhenji"] = "洛清",
  ["illustrator:lq_refg__zhenji"] = "石蝉",
  ["lq__luoshen"] = "洛神",
  [":lq__luoshen"] = "回合开始时，你可以判定，若为黑色，你再次判定，然后你获得所有判定牌。",
  ["lq__qingguo"] = "倾国",
  [":lq__qingguo"] = "你可以将黑色牌当【闪】使用或打出。",
  ["#lq__qingguo"] = "倾国：将黑色牌当【闪】使用或打出。",

  ["$lq__luoshen1"] = "靓妆刻饰，便嬛绰约。",
  ["$lq__luoshen2"] = "绝殊离俗，妖冶娴都。",
  ["$lq__qingguo1"] = "妙丽善舞，佳人难寻。",
  ["$lq__qingguo2"] = "倾城怎比倾国美？",
  ["~lq_refg__zhenji"] = "道阻且长，别离可安。",
}

-- 刘备（界刘备复制人……）
local lq_refg__liubei = General:new(extension, "lq_refg__liubei", "shu", 4)
local lq__rende = fk.CreateActiveSkill{
  name = "lq__rende",
  anim_type = "support",
  min_card_num = 1,
  target_num = 1,
  prompt = "#lq__rende",
  card_filter = function(self, to_select, selected)
    return table.contains(Self:getCardIds("h"), to_select)
  end,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id and Fk:currentRoom():getPlayerById(to_select):getMark("_lq__rende-turn") == 0
  end,
  on_use = function(self, room, effect)
    local target = room:getPlayerById(effect.tos[1])
    local player = room:getPlayerById(effect.from)
    local cards = effect.cards
    local marks = player:getMark("_rende_cards-turn")
    room:moveCardTo(cards, Player.Hand, target, fk.ReasonGive, self.name, nil, false)
    room:addPlayerMark(player, "_rende_cards-turn", #cards)
    room:setPlayerMark(target, "_lq__rende-turn", 1)
    if marks < 2 and marks + #cards >= 2 then
      cards = U.getUniversalCards(room, "b", false)
      local use = U.askForUseRealCard(room, player, cards, nil, self.name, "#lq__rende-ask",
        {expand_pile = cards, bypass_times = false, extraUse = false}, true, true)
      if use then
        use = {
          card = Fk:cloneCard(use.card.name),
          from = player.id,
          tos = use.tos,
        }
        use.card.skillName = self.name
        room:useCard(use)
      end
    end
  end,
}
lq_refg__liubei:addSkill(lq__rende)

Fk:loadTranslationTable{
  ["lq_refg__liubei"] = "刘备",
  ["#lq_refg__liubei"] = "怀德救世",
  ["designer:lq_refg__liubei"] = "洛清",
  ["illustrator:lq_refg__liubei"] = "KayaK",

  ["lq__rende"] = "仁德",
  [":lq__rende"] = "出牌阶段每名角色限一次，你可以将任意张手牌交给一名其他角色，当你以此法给出本回合第二张牌时，你可以视为使用一张基本牌。",
  ["#lq__rende"] = "仁德：将任意张手牌交给一名角色，若此回合交出达到两张，你可以视为使用一张基本牌",
  ["#lq__rende-ask"] = "仁德：你可视为使用一张基本牌",

  ["$lq__rende1"] = "以德服人。",
  ["$lq__rende2"] = "唯贤唯德，能服于人。",
  ["~lq_refg__liubei"] = "这就是桃园吗？",
}

-- 关羽
local lq_refg__guanyu = General:new(extension, "lq_refg__guanyu", "shu", 4)
local lq__wusheng = fk.CreateViewAsSkill{
  name = "lq__wusheng",
  pattern = "slash,duel",
  prompt = "#lq__wusheng",
  interaction = function()
    return UI.ComboBox {choices = {"slash", "duel"}}
  end,
  card_num = 1,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).color == Card.Red
  end,
  view_as = function(self, cards)
    if #cards ~= 1 or self.interaction.data == nil then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    card:addSubcard(cards[1])
    return card
  end,
  enabled_at_play = function(self, player)
    return not player:isNude()
  end,
  enabled_at_response = function(self, player, cardResponsing)
    return not player:isNude()
  end,
  on_acquire = function(self, player, isstart)
    local room = player.room
    table.forEach(room:getOtherPlayers(player), function(p)
      room:handleAddLoseSkills(p, "lq__wusheng&", nil, false, true)
    end)
  end,
  on_lose = function(self, player, isdead)
    local room = player.room
    local main = table.find(room.alive_players, function(p)
      return p:hasSkill(self, true)
    end)
    if not main then
      table.forEach(room:getAlivePlayers(), function(p)
        room:handleAddLoseSkills(p, "-lq__wusheng&", nil, false, true)
      end)
    end
  end
}
local lq__wusheng_rev = fk.CreateViewAsSkill{
  name = "lq__wusheng&",
  pattern = "slash,duel",
  prompt = "#lq__wusheng",
  interaction = function()
    return UI.ComboBox {choices = {"slash", "duel"}}
  end,
  card_num = 1,
  card_filter = lq__wusheng.cardFilter,
  view_as = function(self, cards)
    if #cards ~= 1 or self.interaction.data == nil then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = "lq__wusheng"
    card:addSubcard(cards[1])
    return card
  end,
  enabled_at_play = function(self, player)
    local current = Fk:currentRoom().current
    return not player:isNude() and current and current:hasSkill("lq__wusheng")
  end,
  enabled_at_response = function(self, player, cardResponsing)
    local current = Fk:currentRoom().current
    return not player:isNude() and current and current:hasSkill("lq__wusheng")
  end,
}
Fk:addSkill(lq__wusheng_rev)
lq_refg__guanyu:addSkill(lq__wusheng)

Fk:loadTranslationTable{
  ["lq_refg__guanyu"] = "关羽",
  ["#lq_refg__guanyu"] = "义薄云天",
  ["designer:lq_refg__guanyu"] = "洛清",
  ["cv:lq_refg__guanyu"] = "扬羽Miro",-- 丁翔威
  ["illustrator:lq_refg__guanyu"] = "俊西JUNC",

  ["lq__wusheng"] = "武圣",
  [":lq__wusheng"] = "你和在你回合内的角色可以将红色牌当【杀】或【决斗】使用或打出。",
  ["#lq__wusheng"] = "武圣：将红色牌当【杀】或【决斗】使用或打出",
  ["lq__wusheng&"] = "武圣",
  [":lq__wusheng&"] = "关羽的回合内，你可以将红色牌当【杀】或【决斗】使用或打出。",

  ["$lq__wusheng1"] = "刀锋所向，战无不克！",
  ["$lq__wusheng2"] = "逆贼，哪里走！",
  ["~lq_refg__guanyu"] = "桃园一拜，恩义常在……",
}

-- 张飞
local lq_refg__zhangfei = General:new(extension, "lq_refg__zhangfei", "shu", 4)
local lq__paoxiao = fk.CreateTriggerSkill{
  name = "lq__paoxiao",
  mute = true,
  anim_type = "offensive",
  events = {fk.CardUsing, fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    if target == player and player:hasSkill(self) and room.current == player then
      local logic = room.logic
      local current_event = logic:getCurrentEvent()
      local mark_name = "lq__paoxiao-turn"
      local mark = player:getMark(mark_name)
      if mark == 0 then
        logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
          local use = e.data[1]
          if use.from == player.id and use.card.trueName == "slash" then
            mark = e.id
            return true
          end
          return false
        end, Player.HistoryTurn)
        logic:getEventsOfScope(GameEvent.RespondCard, 1, function (e)
          local use = e.data[1]
          if use.from == player.id and use.card.trueName == "slash" then
            mark = (mark == 0) and e.id or math.min(e.id, mark)
            return true
          end
          return false
        end, Player.HistoryTurn)
        room:setPlayerMark(player, mark_name, mark)
      end
      return mark == current_event.id
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#lq__paoxiao-invoke")
  end,
  on_use = function(self, event, target, player, data)
    player.room:notifySkillInvoked(player, "lq__paoxiao", "drawcard")
    player:broadcastSkillInvoke("lq__paoxiao", 2)
    player:drawCards(1, self.name)
    player.room:setPlayerMark(player, "@@lq__paoxiao-turn", 1)
  end,

  refresh_events = {fk.CardUsing},
  can_refresh = function(self, event, target, player, data)
    if player ~= target or not data.card or player:getMark("@@lq__paoxiao-turn") == 0 then return false end -- 摆一下
    local card = Fk:cloneCard(data.card.name)
    for _, scope in ipairs({Player.HistoryPhase, Player.HistoryTurn, Player.HistoryRound, Player.HistoryGame}) do
      local limit = card.skill:getMaxUseTime(player, scope, card)
      if limit and player:usedCardTimes(data.card.trueName, scope) > limit then return true end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("lq__paoxiao", 1)
    room:doAnimate("InvokeSkill", {
      name = "lq__paoxiao",
      player = player.id,
      skill_type = "offensive",
    })
  end,
}
local lq__paoxiao_tmod = fk.CreateTargetModSkill{
  name = "#lq__paoxiao_tmod",
  bypass_times = function(self, player, skill, scope, card, to)
    return card and player and player:getMark("@@lq__paoxiao-turn") ~= 0
  end,
  bypass_distances = function(self, player, skill, card, to)
    return card and player and player:getMark("@@lq__paoxiao-turn") ~= 0
  end
}
lq__paoxiao:addRelatedSkill(lq__paoxiao_tmod)
lq_refg__zhangfei:addSkill(lq__paoxiao)
Fk:loadTranslationTable{
  ["lq_refg__zhangfei"] = "张飞",
  ["#lq_refg__zhangfei"] = "慑逆江流",
  ["designer:lq_refg__zhangfei"] = "洛清",
  ["cv:lq_refg__zhangfei"] = "冷泉月夜",
  ["illustrator:lq_refg__zhangfei"] = "SONGQIJIN",

  ["lq__paoxiao"] = "咆哮",
  [":lq__paoxiao"] = "当你于一回合内首次使用或打出【杀】后，你可以摸一张牌，然后你本回合使用牌无距离和次数限制。",
  ["#lq__paoxiao-invoke"] = "咆哮：你可以摸一张牌，然后你本回合使用牌无距离和次数限制",
  ["@@lq__paoxiao-turn"] = "咆哮",

  ["$lq__paoxiao1"] = "喝啊！",
  ["$lq__paoxiao2"] = "今，必斩汝马下！",
  ["~lq_refg__zhangfei"] = "桃园一拜，此生…无憾……",
}

-- 诸葛亮（标诸葛亮克隆人……）
local lq_refg__zhugeliang = General:new(extension, "lq_refg__zhugeliang", "shu", 3)
local lq__guanxing = fk.CreateTriggerSkill{
  name = "lq__guanxing",
  anim_type = "control",
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:askForGuanxing(player, room:getNCards(math.min(5, #room.alive_players)))
  end,
}
local lq__kongcheng = fk.CreateTriggerSkill{
  name = "lq__kongcheng",
  anim_type = "defensive",
  events = {fk.TargetConfirming},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
    data.card and table.contains({"slash", "duel"}, data.card.trueName) and player:isKongcheng()
  end,
  on_use = function(self, event, target, player, data)
    AimGroup:cancelTarget(data, player.id)
    return true
  end,
}
lq_refg__zhugeliang:addSkill(lq__guanxing)
lq_refg__zhugeliang:addSkill(lq__kongcheng)
Fk:loadTranslationTable{
  ["lq_refg__zhugeliang"] = "诸葛亮",
  ["#lq_refg__zhugeliang"] = "千古一相",
  ["designer:lq_refg__zhugeliang"] = "洛清",
  ["illustrator:lq_refg__zhugeliang"] = "KayaK",

  ["lq__guanxing"] = "观星",
  [":lq__guanxing"] = "回合开始时，你可以观看牌堆顶的X张牌，然后将任意数量的牌置于牌堆顶，将其余的牌置于牌堆底。（X为存活角色数且至多为5）",
  ["lq__kongcheng"] = "空城",
  [":lq__kongcheng"] = "你成为【杀】或【决斗】的目标时，若你没有手牌，你可以取消之。",

  ["$lq__guanxing1"] = "观今夜天象，知天下大事。",
  ["$lq__guanxing2"] = "知天易，逆天难。",
  ["$lq__kongcheng1"] = "（悠扬的琴音）",
  ["$lq__kongcheng2"] = "（低沉的琴音）",
  ["~lq_refg__zhugeliang"] = "将星陨落，天命难违。",
}

-- 赵云
local lq_refg__zhaoyun = General:new(extension, "lq_refg__zhaoyun", "shu", 4)
local lq__longdan = fk.CreateViewAsSkill{
  name = "lq__longdan",
  pattern = "slash,jink",
  interaction = function()
    local names = {}
    if Fk.currentResponsePattern == nil and Self:canUse(Fk:cloneCard("slash")) then
      table.insertIfNeed(names, "slash")
    else
      for _, name in ipairs({"slash", "jink"}) do
        if Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(Fk:cloneCard(name)) then
          table.insertIfNeed(names, name)
        end
      end
    end
    if #names == 0 then return end
    return UI.ComboBox {choices = names}
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeBasic
  end,
  view_as = function(self, cards)
    if #cards ~= 1 or self.interaction.data == nil then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    card:addSubcard(cards[1])
    return card
  end,
  enabled_at_play = function(self, player)
    return not player:isNude()
  end,
  enabled_at_response = function(self, player, cardResponsing)
    return not player:isNude()
  end,
}
local lq__longdan_trig = fk.CreateTriggerSkill{
  name = "#lq__longdan_trig",
  mute = true,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    local move_event = room.logic:getCurrentEvent()
    local parent_event = move_event.parent
    if parent_event and (parent_event.event == GameEvent.UseCard or parent_event.event == GameEvent.RespondCard) then
      local parent_data = parent_event.data[1] ---@type CardUseStruct
      if parent_data.from == player.id and parent_data.card and table.contains(parent_data.card.skillNames, "lq__longdan") then
        return room:getCardArea(parent_data.card) == Card.DiscardPile
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(room:getOtherPlayers(player, false), Util.IdMapper)
    local move_event = room.logic:getCurrentEvent()
    local parent_event = move_event.parent
    local parent_card
    local cards = {}
    if parent_event and (parent_event.event == GameEvent.UseCard or parent_event.event == GameEvent.RespondCard) then
      local parent_data = parent_event.data[1] ---@type CardUseStruct
      if parent_data.from == player.id and parent_data.card then
        parent_card = parent_data.card
        cards = table.map(Card:getIdList(parent_card), function(cid)
          return Fk:getCardById(cid):toLogString()
        end)
      end
    end
    local to = room:askForChoosePlayers(player, targets, 1, 1, "#lq__longdan-give:::" .. table.concat(cards, ","), "lq__longdan")
    if to[1] then
      self.cost_data = {to[1], Card:getIdList(parent_card)}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data[1])
    local cards = self.cost_data[2]
    room:obtainCard(to, cards, true, fk.ReasonGive, player.id, "lq__longdan")
  end
}
lq__longdan:addRelatedSkill(lq__longdan_trig)
lq_refg__zhaoyun:addSkill(lq__longdan)
Fk:loadTranslationTable{
  ["lq_refg__zhaoyun"] = "赵云",
  ["#lq_refg__zhaoyun"] = "枪贯天涯",
  ["designer:lq_refg__zhaoyun"] = "洛清",
  ["illustrator:lq_refg__zhaoyun"] = "DH",

  ["lq__longdan"] = "龙胆",
  [":lq__longdan"] = "你可以将基本牌当【杀】或【闪】使用或打出，此牌进入弃牌堆后，你可以将之交给一名其他角色。",
  ["#lq__longdan"] = "龙胆：将基本牌当【杀】或【闪】使用或打出，此牌进入弃牌堆后，你可以将之交给一名其他角色",
  ["#lq__longdan-give"] = "龙胆：你可以将%arg交给一名其他角色",

  ["$lq__longdan1"] = "龙威虎胆，斩敌破阵！",
  ["$lq__longdan2"] = "进退自如，游刃有余！",
  ["~lq_refg__zhaoyun"] = "你们谁…还敢再上……",
}

-- 马超（界马超复制人……）
local lq_refg__machao = General:new(extension, "lq_refg__machao", "shu", 4)
local lq__tieqi = fk.CreateTriggerSkill{
  name = "lq__tieqi",
  anim_type = "offensive",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
      data.card.trueName == "slash" and not player.room:getPlayerById(data.to).dead
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if room:askForSkillInvoke(player, self.name, nil, "#lq__tieqi-invoke::"..data.to) then
      room:doIndicate(player.id, {data.to})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.to)
    room:addPlayerMark(to, "@@lq__tieqi-turn")
    room:addPlayerMark(to, MarkEnum.UncompulsoryInvalidity .. "-turn")
    data.disresponsiveList = data.disresponsiveList or {}
    table.insertIfNeed(data.disresponsiveList, data.to)
  end,
}
local lq__mashu = fk.CreateDistanceSkill{
  name = "lq__mashu",
  frequency = Skill.Compulsory,
  correct_func = function(self, from, to)
    if from:hasSkill(self) then
      return -1
    end
  end,
}
lq_refg__machao:addSkill(lq__tieqi)
lq_refg__machao:addSkill(lq__mashu) -- 传奇马术不能丢（
Fk:loadTranslationTable{
  ["lq_refg__machao"] = "马超",
  ["#lq_refg__machao"] = "神威天将",
  ["designer:lq_refg__machao"] = "洛清",
  ["illustrator:lq_refg__machao"] = "木美人&张帅&KayaK",

  ["lq__tieqi"] = "铁骑",
  [":lq__tieqi"] = "当你使用【杀】指定目标后，你可以令其本回合内非锁定技失效且不可响应此【杀】。",
  ["lq__mashu"] = "马术",
  [":lq__mashu"] = "锁定技，你与其他角色的距离-1。",
  ["@@lq__tieqi-turn"] = "铁骑",
  ["#lq__tieqi-invoke"] = "铁骑：你可以令 %dest 本回合内非锁定技失效且不可响应此【杀】",

  ["$lq__tieqi1"] = "目标敌阵，全军突击！",
  ["$lq__tieqi2"] = "敌人阵型已乱，随我杀！",
  ["~lq_refg__machao"] = "请将我，葬在西凉……",
}

-- 黄月英（标黄月英复制人……？）
local lq_refg__huangyueying = General:new(extension, "lq_refg__huangyueying", "shu", 3, 3, General.Female)
local lq__jizhi = fk.CreateTriggerSkill{
  name = "lq__jizhi",
  anim_type = "drawcard",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.card and data.card.type == Card.TypeTrick then
      local card = data.card
      return not card:isVirtual() or #card.subcards == 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room

    local cards = room:getNCards(2)

    local result = room:askForArrangeCards(player, self.name, {"Top", cards, "Bottom", "toObtain"}, "#lq__jizhi-guanxing", true, 2, {2, 2, 1}, {0, 0, 0})
    room:moveCardTo(result[3], Player.Hand, player, fk.ReasonPrey, self.name, nil, false, player.id)
    local top = result[1]
    local bottom = result[2]
    for i = #top, 1, -1 do
      table.insert(room.draw_pile, 1, top[i])
    end
    for i = 1, #bottom, 1 do
      table.insert(room.draw_pile, bottom[i])
    end

    room:sendLog{
      type = "#GuanxingResult",
      from = player.id,
      arg = #top,
      arg2 = #bottom,
    }
  end
}
local lq__qicai = fk.CreateTargetModSkill{
  name = "lq__qicai",
  frequency = Skill.Compulsory,
  bypass_distances = function(self, player, skill, card)
    return player:hasSkill(self) and card and card.type == Card.TypeTrick
  end,
}
lq_refg__huangyueying:addSkill(lq__jizhi)
lq_refg__huangyueying:addSkill(lq__qicai)
Fk:loadTranslationTable{
  ["lq_refg__huangyueying"] = "黄月英",
  ["#lq_refg__huangyueying"] = "草堂春旧",
  ["designer:lq_refg__huangyueying"] = "洛清",
  ["illustrator:lq_refg__huangyueying"] = "KayaK",

  ["lq__jizhi"] = "集智",
  [":lq__jizhi"] = "当你使用非转化锦囊牌时，可以观看牌堆顶两张牌，获得至多一张，然后将剩下的牌以任意顺序置于牌堆顶或牌堆底。",
  ["#lq__jizhi-guanxing"] = "集智：请调整这些牌的顺序，你可以获得至多一张牌",
  ["lq__qicai"] = "奇才",
  [":lq__qicai"] = "锁定技，你使用锦囊牌无距离限制。",

  ["$lq__jizhi1"] = "哼哼～",
  ["$lq__jizhi2"] = "哼～",
  ["~lq_refg__huangyueying"] = "亮……",
}

-- 孙权（标孙权复制人）
local lq_refg__sunquan = General:new(extension, "lq_refg__sunquan", "wu", 4)
local lq__zhiheng = fk.CreateActiveSkill{
  name = "lq__zhiheng",
  prompt = "#lq__zhiheng",
  anim_type = "drawcard",
  max_phase_use_time = 1,
  target_num = 0,
  min_card_num = 1,
  card_filter = function(self, to_select)
    return not Self:prohibitDiscard(Fk:getCardById(to_select))
  end,
  on_use = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    room:throwCard(effect.cards, self.name, from, from)
    if from:isAlive() then
      from:drawCards(#effect.cards, self.name)
    end
  end,
}
lq_refg__sunquan:addSkill(lq__zhiheng)
Fk:loadTranslationTable{
  ["lq_refg__sunquan"] = "孙权",
  ["#lq_refg__sunquan"] = "大江东去",
  ["designer:lq_refg__sunquan"] = "洛清",
  ["illustrator:lq_refg__sunquan"] = "KayaK",

  ["lq__zhiheng"] = "制衡",
  [":lq__zhiheng"] = "出牌阶段限一次，你可以弃置任意张牌，然后摸等量张牌。",
  ["#lq__zhiheng"] = "制衡：弃置任意张牌，然后摸等量张牌",

  ["$lq__zhiheng1"] = "容我三思。",
  ["$lq__zhiheng2"] = "且慢。",
  ["~lq_refg__sunquan"] = "父亲，大哥，仲谋愧矣……",
}

-- 甘宁（标甘宁复制人……？）
local lq_refg__ganning = General:new(extension, "lq_refg__ganning", "wu", 4)
local lq__qixi = fk.CreateViewAsSkill{
  name = "lq__qixi",
  anim_type = "control",
  prompt = "#lq__qixi",
  pattern = "dismantlement",
  card_filter = function(self, to_select, selected)
    if #selected == 1 then return false end
    return Fk:getCardById(to_select).color == Card.Black
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("dismantlement")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
  enabled_at_response = function (self, player, response)
    return not response
  end
}
local lq__qixi_trig = fk.CreateTriggerSkill{
  name = "#lq__qixi_trig",
  mute = true,
  refresh_events = {fk.CardEffecting, fk.CardUseFinished},
  can_refresh = function(self, event, target, player, data)
    return player.id == data.from and table.contains(data.card.skillNames, "lq__qixi")
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local tos = TargetGroup:getRealTargets(data.tos)
    for _, pid in ipairs(tos) do
      local to = room:getPlayerById(pid)
      if to.dead then return end
      local mark = to:getTableMark("_lq__qixi")
      if event == fk.CardEffecting then
        mark[tostring(player.id)] = (mark[tostring(player.id)] or 0) + 1
      else
        local v = (mark[tostring(player.id)] or 0) - 1
        if v < 1 then v = nil end
        mark[tostring(player.id)] = v
        if #mark == 0 then mark = nil end
      end
      room:setPlayerMark(to, "_lq__qixi", mark)
    end
  end
}
local lq__qixi_vis = fk.CreateVisibilitySkill{
  name = "#lq__qixi_vis",
  card_visible = function(self, player, card)
    local room = Fk:currentRoom()
    local owner = room:getCardOwner(card)
    if owner and room:getCardArea(card) == Player.Hand then
      local mark = owner:getTableMark("_lq__qixi")[tostring(player.id)]
      if mark and mark > 0 then return true end
    end
  end
}
lq__qixi:addRelatedSkill(lq__qixi_vis)
lq__qixi:addRelatedSkill(lq__qixi_trig)
lq_refg__ganning:addSkill(lq__qixi)
Fk:loadTranslationTable{
  ["lq_refg__ganning"] = "甘宁",
  ["#lq_refg__ganning"] = "且闻铃响",
  ["designer:lq_refg__ganning"] = "洛清",
  ["illustrator:lq_refg__ganning"] = "KayaK",

  ["lq__qixi"] = "奇袭",
  [":lq__qixi"] = "你可以将黑色牌当【过河拆桥】使用，此牌生效时，目标手牌对你可见直到结算结束。",
  ["#lq__qixi"] = "奇袭：将黑色牌当【过河拆桥】使用，此牌生效时，目标手牌对你可见直到结算结束",
  ["#lq__qixi_trig"] = "奇袭",
  ["#lq__qixi_vis"] = "奇袭",

  ["$lq__qixi1"] = "接招吧！",
  ["$lq__qixi2"] = "你的牌太多啦！",
  ["~lq_refg__ganning"] = "二十年后，又是一条好汉……",
}

-- 吕蒙（神吕蒙复制人……）
local lq_refg__lvmeng = General:new(extension, "lq_refg__lvmeng", "wu", 4)
Fk:addPoxiMethod{
  name = "lq__shelie",
  card_filter = function(to_select, selected, data)
    if table.contains(data[2], to_select) then return true end
    local suit = Fk:getCardById(to_select).suit
    return table.every(data[2], function (id)
      return Fk:getCardById(id).suit ~= suit
    end)
  end,
  feasible = function(selected)
    return true
  end,
}
local lq__shelie = fk.CreateTriggerSkill{
  name = "lq__shelie",
  anim_type = "drawcard",
  events = {fk.EventPhaseProceeding},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Draw and not player._phase_end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = table.slice(room.draw_pile, 1, 6)
    room:showCards(cards, player)
    local get = {}
    for _, id in ipairs(cards) do
      local suit = Fk:getCardById(id).suit
      if table.every(get, function (id2)
        return Fk:getCardById(id2).suit ~= suit
      end) then
        table.insert(get, id)
      end
    end
    get = room:askForArrangeCards(player, self.name, cards, "#lq__shelie-choose", false, 0, {5, 4}, {0, #get}, ".", "lq__shelie", {{}, get})[2]
    if #get > 0 then
      room:obtainCard(player, get, true, fk.ReasonPrey)
    end
    cards = table.filter(cards, function(id) return room:getCardArea(id) == Card.Processing end)
    if #cards > 0 then
      room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonJustMove, self.name)
    end
    player._phase_end = true
  end,
}
local lq__gongxin = fk.CreateActiveSkill{
  name = "lq__gongxin",
  anim_type = "control",
  prompt = "#lq__gongxin-active",
  target_num = 1,
  card_num = 0,
  max_phase_use_time = 1,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id and not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local cards = target.player_cards[Player.Hand]
    local hearts = table.filter(cards, function (id) return Fk:getCardById(id).suit == Card.Heart end)
    local ids, choice = U.askforChooseCardsAndChoice(player, hearts, {"lq__gongxin_discard", "lq__gongxin_put"},
    self.name, "#lq__gongxin-view::" .. target.id, {"Cancel"}, 1, 1, cards)
    if choice == "lq__gongxin_discard" then
      room:throwCard(ids, self.name, target, player)
    elseif choice == "lq__gongxin_put" then
      room:moveCardTo(ids, Card.DrawPile, nil, fk.ReasonPut, self.name, nil, true)
    end
  end,
}
lq_refg__lvmeng:addSkill(lq__shelie)
lq_refg__lvmeng:addSkill(lq__gongxin)
Fk:loadTranslationTable{
  ["lq_refg__lvmeng"] = "吕蒙",
  ["#lq_refg__lvmeng"] = "白衣渡江",
  ["designer:lq_refg__lvmeng"] = "洛清",
	["illustrator:lq_refg__lvmeng"] = "樱花闪乱",

  ["lq__shelie"] = "涉猎",
  [":lq__shelie"] = "摸牌阶段，你可以改为展示牌堆顶五张牌，获得其中任意张不同花色的牌，弃置其余牌。",
  ["lq__gongxin"] = "攻心",
  [":lq__gongxin"] = "出牌阶段限一次，你可以观看一名其他角色的手牌，然后你可以展示其中一张<font color='red'>♥</font>牌并弃置或置于牌堆顶。",
  ["#lq__shelie-choose"] = "涉猎：获得不同花色的牌各一张",
  ["#lq__gongxin-active"] = "发动 攻心，观看一名其他角色的手牌",
  ["#lq__gongxin-view"] = "攻心：观看%dest的手牌",
  ["lq__gongxin_discard"] = "弃置此牌",
  ["lq__gongxin_put"] = "将此牌置于牌堆顶",

  ["$lq__shelie1"] = "兵书熟读，了然于胸。",
  ["$lq__shelie2"] = "勤以修身，学以报国。",
  ["$lq__gongxin1"] = "洞若观火，运筹帷幄。",
  ["$lq__gongxin2"] = "哼，早知如此。",
  ["~lq_refg__lvmeng"] = "你，给我等着！",
}

-- 周瑜（界周瑜复制人……？）
local lq_refg__zhouyu = General:new(extension, "lq_refg__zhouyu", "wu", 4)
local lq__yingzi = fk.CreateTriggerSkill{
  name = "lq__yingzi",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.DrawNCards},
  on_use = function(self, event, target, player, data)
    data.n = 3
  end,
}
local lq__yingzi_maxcards = fk.CreateMaxCardsSkill{
  name = "#lq__yingzi_maxcards",
  main_skill = lq__yingzi,
  fixed_func = function(self, player)
    if player:hasShownSkill(lq__yingzi) then
      return 3
    end
  end
}
local lq__fanjian = fk.CreateActiveSkill{
  name = "lq__fanjian",
  anim_type = "control",
  card_num = 1,
  target_num = 1,
  prompt = "#ex__fanjian",
  max_phase_use_time = 1,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
  end,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local cid = effect.cards[1]
    local player = room:getPlayerById(effect.from)
    player:showCards(cid)
    if player.dead then return end
    local suit = Fk:getCardById(cid).suit
    local suitString = Fk:getCardById(cid):getSuitString(true)
    local target = room:getPlayerById(effect.tos[1])
    room:obtainCard(target.id, cid, true, fk.ReasonGive)
    if target.dead then return end
    local choices = { "loseHp", "lq__fanjian_show:::" .. suitString }
    local all_choices = table.simpleClone(choices)
    if (target:isKongcheng() and table.every(target:getCardIds(Player.Equip), function (id)
      return Fk:getCardById(id).suit ~= suit
    end)) or suit == Card.NoSuit then table.remove(choices) end
    if target.hp <= 0 then table.remove(choices, 1) end
    if #choices == 0 then return end
    local choice = room:askForChoice(player, choices, self.name, "#lq__fanjian-choose:" .. target.id, false, all_choices)
    if choice == "loseHp" then
      room:loseHp(target, 1, self.name)
    else
      if target.dead then return end
      local discards = table.filter(target:getCardIds{ Player.Hand, Player.Equip }, function(id)
        return Fk:getCardById(id).suit == suit and not target:prohibitDiscard(Fk:getCardById(id))
      end)
      room:throwCard(discards, self.name, target, target)
      target:showCards(target:getCardIds(Player.Hand))
    end
  end,
}
lq__yingzi:addRelatedSkill(lq__yingzi_maxcards)
lq_refg__zhouyu:addSkill(lq__yingzi)
lq_refg__zhouyu:addSkill(lq__fanjian)
Fk:loadTranslationTable{
  ["lq_refg__zhouyu"] = "周瑜",
  ["#lq_refg__zhouyu"] = "从此赤壁",
  ["designer:lq_refg__zhouyu"] = "洛清",
  ["illustrator:lq_refg__zhouyu"] = "KayaK",

  ["lq__yingzi"] = "英姿",
  [":lq__yingzi"] = "锁定技，你的摸牌阶段摸牌数和手牌上限改为3。",
  ["lq__fanjian"] = "反间",
  [":lq__fanjian"] = "出牌阶段限一次，你可以展示一张手牌并交给一名其他角色，然后选择一项，令其：1.失去1点体力；"..
  "2.弃置所有与此牌花色相同的牌并展示所有手牌。",
  ["#lq__fanjian"] = "反间：展示一张手牌并交给一名其他角色，然后令其弃置所有此花色牌或失去1点体力",
  ["#lq__fanjian-choose"] = "反间：请选择一个选项，令 %src 执行之",
  ["lq__fanjian_show"] = "弃置所有的%arg牌，展示手牌",

  ["$lq__yingzi1"] = "哈哈哈哈哈哈哈哈！",
  ["$lq__yingzi2"] = "伯符，且看我这一手！",
  ["$lq__fanjian1"] = "与我为敌，就当这般生不如死！",
  ["$lq__fanjian2"] = "抉择吧！在苦与痛的地狱中！",
  ["~lq_refg__zhouyu"] = "既生瑜，何生亮！……既生瑜，何生亮……！",
}

-- 陆逊（界陆逊复制人……？）
local lq_refg__luxun = General:new(extension, "lq_refg__luxun", "wu", 3, 3)
local lq__qianxun = fk.CreateTriggerSkill{
  name = "lq__qianxun",
  anim_type = "drawcard",
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.from ~= player.id and
    data.card and data.card.type == Card.TypeTrick and #AimGroup:getAllTargets(data.tos) == 1
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local discards = room:askForDiscard(player, 1, #player:getCardIds("he"), true, self.name, true, nil, "#lq__qianxun-invoke", true)
    if #discards ~= 0 then
      self.cost_data = discards
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(self.cost_data, self.name, player, player)
    room:addPlayerMark(player, "@lq__qianxun", #self.cost_data)
  end,
}
local lq__qianxun_delay = fk.CreateTriggerSkill{
  name = "#lq__qianxun_delay",
  mute = true,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return not player.dead and player:getMark("@lq__qianxun") ~= 0
  end,
  on_trigger = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(player:getMark("@lq__qianxun"), "lq__qianxun")
    room:setPlayerMark(player, "@lq__qianxun", 0)
  end,
}
local lq__lianying = fk.CreateTriggerSkill{
  name = "lq__lianying",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not (player:hasSkill(self) and player:isKongcheng()) then return false end
    for _, move in ipairs(data) do
      if move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand then
            return true
          end
        end
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local n = 0
    for _, move in ipairs(data) do
      if move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand then
            n = n + 1
          end
        end
      end
    end
    local players = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, n,
      "#lq__lianying-invoke:::"..n, self.name)
    if #players > 0 then
      room:sortPlayersByAction(players)
      self.cost_data = {tos = players}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, pid in ipairs(self.cost_data.tos) do
      local p = room:getPlayerById(pid)
      if not p.dead then p:drawCards(1, self.name) end
    end
  end,
}
lq__qianxun:addRelatedSkill(lq__qianxun_delay)
lq_refg__luxun:addSkill(lq__qianxun)
lq_refg__luxun:addSkill(lq__lianying)
Fk:loadTranslationTable{
  ["lq_refg__luxun"] = "陆逊",
  ["#lq_refg__luxun"] = "举火燎天",
  ["designer:lq_refg__luxun"] = "洛清",
	["illustrator:lq_refg__luxun"] = "depp",

  ["lq__qianxun"] = "谦逊",
  [":lq__qianxun"] = "其他角色使用锦囊牌指定你为唯一目标后，你可以弃置任意张牌，若如此做，本回合结束时，你摸等量张牌。",
  ["lq__lianying"] = "连营",
  [":lq__lianying"] = "当你失去所有手牌后，你可以令至多等量名角色摸一张牌。",
  ["#lq__qianxun-invoke"] = "谦逊：你可以弃置任意张牌，若如此做，本回合结束时，你摸等量张牌。",
  ["#lq__lianying-invoke"] = "连营：你可以令至多 %arg 名角色摸一张牌",
  ["@lq__qianxun"] = "谦逊",

  ["$lq__qianxun1"] = "满招损，谦受益。",
  ["$lq__qianxun2"] = "谦谦君子，温润如玉。",
  ["$lq__lianying1"] = "生生不息，源源不绝。",
  ["$lq__lianying2"] = "失之淡然，得之坦然。",
  ["~lq_refg__luxun"] = "我的未竟之业……",
}

-- 大乔（标大乔复制人……）
local lq_refg__daqiao = General:new(extension, "lq_refg__daqiao", "wu", 3, 3, General.Female)
local lq__liuli = fk.CreateTriggerSkill{
  name = "lq__liuli",
  anim_type = "defensive",
  events = {fk.TargetConfirming},
  can_trigger = function(self, event, target, player, data)
    local ret = target == player and player:hasSkill(self) and
      data.card.trueName == "slash"
    if ret then
      local room = player.room
      local from = room:getPlayerById(data.from)
      for _, p in ipairs(room.alive_players) do
        if p ~= player and p.id ~= data.from and not from:isProhibited(p, data.card) then
          return true
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local prompt = "#lq__liuli-target"
    local targets = {}
    local from = room:getPlayerById(data.from)
    for _, p in ipairs(room.alive_players) do
      if p ~= player and p.id ~= data.from and not from:isProhibited(p, data.card) then
        table.insert(targets, p.id)
      end
    end
    if #targets == 0 then return false end
    local plist, cid = room:askForChooseCardAndPlayers(player, targets, 1, 1, nil, prompt, self.name, true)
    if #plist > 0 then
      self.cost_data = {tos = plist, cards = {cid}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = self.cost_data.tos[1]
    room:throwCard(self.cost_data.cards, self.name, player, player)
    AimGroup:cancelTarget(data, player.id)
    AimGroup:addTargets(room, data, to)
  end,
}
local lq__guose = fk.CreateViewAsSkill{
  name = "lq__guose",
  prompt = "#lq__guose",
  anim_type = "control",
  pattern = "indulgence",
  card_filter = function(self, to_select, selected)
    if #selected == 1 then return false end
    return Fk:getCardById(to_select).suit == Card.Diamond
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("indulgence")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
  enabled_at_response = function (self, player, response)
    return not response
  end
}
lq_refg__daqiao:addSkill(lq__liuli)
lq_refg__daqiao:addSkill(lq__guose)
Fk:loadTranslationTable{
  ["lq_refg__daqiao"] = "大乔",
  ["#lq_refg__daqiao"] = "花落梦中",
  ["designer:lq_refg__daqiao"] = "洛清",
	["illustrator:lq_refg__daqiao"] = "KayaK",

  ["lq__liuli"] = "流离",
  [":lq__liuli"] = "当你成为【杀】的目标时，你可以弃置一张牌并选择另一名可以成为此【杀】目标的角色，若如此做，该角色代替你成为此【杀】的目标。",
  ["#lq__liuli-target"] = "流离：你可以弃置一张牌，将【杀】的目标转移给一名其他角色",
  ["lq__guose"] = "国色",
  [":lq__guose"] = "你可以将<font color='red'>♦</font>牌当【乐不思蜀】使用。",
  ["#lq__guose"] = "国色：将<font color='red'>♦</font>牌当【乐不思蜀】使用",
  ["$lq__liuli1"] = "交给你了。",
  ["$lq__liuli2"] = "你来嘛～",
  ["$lq__guose1"] = "请休息吧。",
  ["$lq__guose2"] = "你累了。",
  ["~lq_refg__daqiao"] = "伯符，我去了……",
}

-- 孙尚香（标孙尚香复制人……）
local lq_refg__sunshangxiang = General:new(extension, "lq_refg__sunshangxiang", "wu", 3, 3, General.Female)
local lq__jieyin = fk.CreateActiveSkill{
  name = "lq__jieyin",
  prompt = "#lq__jieyin",
  anim_type = "support",
  max_phase_use_time = 1,
  card_filter = function(self, to_select, selected)
    return #selected < 2 and not Self:prohibitDiscard(Fk:getCardById(to_select))
  end,
  target_filter = function(self, to_select, selected)
    local target = Fk:currentRoom():getPlayerById(to_select)
    return target:isWounded() and target:isMale() and #selected < 1 and to_select ~= Self.id
  end,
  target_num = 1,
  card_num = 2,
  on_use = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:throwCard(effect.cards, self.name, from, from)
    if target:isAlive() and target:isWounded() then
      room:recover({
        who = room:getPlayerById(effect.tos[1]),
        num = 1,
        recoverBy = from,
        skillName = self.name
      })
    end
    if from:isAlive() and from:isWounded() then
      room:recover({
        who = from,
        num = 1,
        recoverBy = from,
        skillName = self.name
      })
    end
  end
}
local lq__xiaoji = fk.CreateTriggerSkill{
  name = "lq__xiaoji",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return end
    for _, move in ipairs(data) do
      if move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerEquip then
            return true
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(2, self.name)
  end,
}
lq_refg__sunshangxiang:addSkill(lq__jieyin)
lq_refg__sunshangxiang:addSkill(lq__xiaoji)
Fk:loadTranslationTable{
  ["lq_refg__sunshangxiang"] = "孙尚香",
  ["#lq_refg__sunshangxiang"] = "恋姬无双",
  ["designer:lq_refg__sunshangxiang"] = "洛清",
	["illustrator:lq_refg__sunshangxiang"] = "KayaK",

  ["lq__jieyin"] = "结姻",
  [":lq__jieyin"] = "出牌阶段限一次，你可以弃置两张牌并选择一名已受伤的男性角色，然后你与其各回复1点体力。",
  ["#lq__jieyin"] = "结姻：弃置两张牌并选择一名已受伤的男性角色，你与其各回复1点体力",
  ["lq__xiaoji"] = "枭姬",
  [":lq__xiaoji"] = "当你失去装备区的装备牌后，你可以摸两张牌。",

  ["$lq__jieyin1"] = "夫君，身体要紧。",
  ["$lq__jieyin2"] = "他好，我也好。",
  ["$lq__xiaoji1"] = "哼！",
  ["$lq__xiaoji2"] = "看我的厉害！",
  ["~lq_refg__sunshangxiang"] = "不，还不可以死……",
}

-- 张角（标张角复制人……？）
local lq_refg__zhangjiao = General:new(extension, "lq_refg__zhangjiao", "qun", 3)
local lq__tianzai = fk.CreateTriggerSkill{
  name = "lq__tianzai",
  anim_type = "offensive",
  events = {fk.CardUsing, fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and data.card.name == "jink" and #player.room.alive_players > 2
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#lq__tianzai-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".|.|spade",
    }
    room:judge(judge)
    if judge.card.suit == Card.Spade then
      local targets = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player, false), Util.IdMapper), 2, 2, "#lq__tianzai-choose", self.name, false)
      if #targets == 2 then
        room:sortPlayersByAction(targets)
        local toa, tob = room:getPlayerById(targets[1]), room:getPlayerById(targets[2])
        local toa_hp, tob_hp = toa.hp, tob.hp
        local x = toa_hp - tob_hp
        if x > 0 then
          room:loseHp(toa, x, self.name)
          room:recover{
            who = tob,
            num = x,
            skillName = self.name
          }
        elseif x < 0 then
          room:recover{
            who = toa,
            num = -x,
            skillName = self.name
          }
          room:loseHp(tob, -x, self.name)
        end
      end
    end
end,
}
local lq__guidao = fk.CreateTriggerSkill{
  name = "lq__guidao",
  anim_type = "control",
  events = {fk.AskForRetrial},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askForCard(player, 1, 1, true, self.name, true, ".|.|spade,club|hand,equip", "#lq__guidao-ask::" .. target.id .. ":" .. data.reason)
    if card[1] then
      self.cost_data = card[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:retrial(Fk:getCardById(self.cost_data), player, data, self.name, true)
  end,
}
lq_refg__zhangjiao:addSkill(lq__tianzai)
lq_refg__zhangjiao:addSkill(lq__guidao)
Fk:loadTranslationTable{
  ["lq_refg__zhangjiao"] = "张角",
  ["#lq_refg__zhangjiao"] = "时代的先驱者",
  ["designer:lq_refg__zhangjiao"] = "洛清",
	["illustrator:lq_refg__zhangjiao"] = "凡果",

  ["lq__tianzai"] = "天灾",
  [":lq__tianzai"] = "当你使用或打出【闪】时，你可以判定，若结果为♠，交换两名其他角色的体力值（视为失去或回复体力）。",
  ["lq__guidao"] = "鬼道",
  [":lq__guidao"] = "一名角色的判定牌生效前，你可以用黑色牌替换之。",
  ["#lq__tianzai-invoke"] = "天灾：你可以判定，若结果为♠，交换两名其他角色的体力值（视为失去或回复体力）",
  ["#lq__tianzai-choose"] = "天灾：选择两名其他角色，交换它们的体力值（视为失去或回复体力）",
  ["#lq__guidao-ask"] = "鬼道：你可以用黑色牌替换 %dest 的 %arg 判定",

  ["$lq__tianzai1"] = "聚天之气，行天之道！",
  ["$lq__tianzai2"] = "看着吧，这改变乱世的力量！",
  ["$lq__guidao1"] = "鬼道莫测，诡变无穷！",
  ["$lq__guidao2"] = "鬼道大开，峰回路转！",
  ["~lq_refg__zhangjiao"] = "黄天既覆，苍生何存……",
}

-- 吕布
local lq_refg__lvbu = General:new(extension, "lq_refg__lvbu", "qun", 4)
local lq__wushuang = fk.CreateTriggerSkill{
  name = "lq__wushuang",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card and table.contains({"slash", "duel"}, data.card.trueName) and
    #TargetGroup:getRealTargets(data.tos) ~= 0 and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = Fk:cloneCard(data.card.name)
    card.skillName = self.name
    room:useVirtualCard(data.card.name, nil, player, table.map(TargetGroup:getRealTargets(data.tos), Util.Id2PlayerMapper), self.name, false)
  end,
}
lq_refg__lvbu:addSkill(lq__wushuang)
Fk:loadTranslationTable{
  ["lq_refg__lvbu"] = "吕布",
  ["#lq_refg__lvbu"] = "最强神话",
  ["designer:lq_refg__lvbu"] = "洛清",
  ["cv:lq_refg__lvbu"] = "金垚",
  ["illustrator:lq_refg__lvbu"] = "张帅",

  ["lq__wushuang"] = "无双",
  [":lq__wushuang"] = "锁定技，每回合限一次，你使用【杀】和【决斗】时，视为对同目标使用同名牌。",
  ["#lq__wushuang-use"] = "无双：你须视为使用一张 %arg",

  ["$lq__wushuang1"] = "还有哪个敢挑战我！？",
  ["$lq__wushuang2"] = "三个齐上，也不是我的对手！",
  ["~lq_refg__lvbu"] = "我竟然输了……不可能！",
}

-- 貂蝉（标貂蝉复制人……）
local lq_refg__diaochan = General:new(extension, "lq_refg__diaochan", "qun", 3, 3, General.Female)
local lq__lijian = fk.CreateActiveSkill{
  name = "lq__lijian",
  prompt = "#lq__lijian",
  anim_type = "offensive",
  max_phase_use_time = 1,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and not Self:prohibitDiscard(Fk:getCardById(to_select))
  end,
  target_filter = function(self, to_select, selected)
    if #selected < 2 and to_select ~= Self.id then
      local target = Fk:currentRoom():getPlayerById(to_select)
      return target:isMale() and (#selected == 0 or
      target:canUseTo(Fk:cloneCard("duel"), Fk:currentRoom():getPlayerById(selected[1])))
    end
  end,
  target_num = 2,
  min_card_num = 1,
  on_use = function(self, room, use)
    local player = room:getPlayerById(use.from)
    room:throwCard(use.cards, self.name, player, player)
    local duel = Fk:cloneCard("duel")
    duel.skillName = self.name
    local new_use = { ---@type CardUseStruct
      from = use.tos[2],
      tos = { { use.tos[1] } },
      card = duel,
    }
    room:useCard(new_use)
  end,
  target_tip = function(self, to_select, selected, _, __, selectable, ____)
    if not selectable then return end
    if #selected == 0 or (#selected > 0 and selected[1] == to_select) then
      return "lq__lijian_tip_1"
    else
      return "lq__lijian_tip_2"
    end
  end,
}
local lq__biyue = fk.CreateTriggerSkill{
  name = "lq__biyue",
  anim_type = "drawcard",
  events = {fk.TurnEnd},
  on_use = function(self, event, target, player, data)
    player:drawCards(1, self.name)
  end,
}
lq_refg__diaochan:addSkill(lq__lijian)
lq_refg__diaochan:addSkill(lq__biyue)
Fk:loadTranslationTable{
  ["lq_refg__diaochan"] = "貂蝉",
  ["#lq_refg__diaochan"] = "诉衷与月",
  ["designer:lq_refg__diaochan"] = "洛清",
	["illustrator:lq_refg__diaochan"] = "KayaK（原）",

  ["lq__lijian"] = "离间",
  [":lq__lijian"] = "出牌阶段限一次，你可以弃置一张牌并选择两名其他男性角色，后选择的角色视为对先选择的角色使用一张【决斗】。",
  ["#lq__lijian"] = "离间：弃置一张手牌并选择两名其他男性角色，后选择的角色视为对先选择的角色使用一张【决斗】",
  ["lq__lijian_tip_1"] = "先出杀",
  ["lq__lijian_tip_2"] = "后出杀",
  ["lq__biyue"] = "闭月",
  [":lq__biyue"] = "回合结束时，你可以摸一张牌。",

  ["$lq__lijian1"] = "嗯呵呵～～呵呵～～",
  ["$lq__lijian2"] = "夫君，你要替妾身作主啊……",
  ["$lq__biyue1"] = "失礼了～",
  ["$lq__biyue2"] = "羡慕吧～",
  ["~lq_refg__diaochan"] = "父亲大人，对不起……",
}

return extension